package com.hnx.admin.json;


import com.hnx.admin.api.http.HttpStatusAPI;

import java.util.HashMap;

/*
创建人： 倔强的头发
创建时间：2025/5/21
功能描述:

*/
public class ResultJson extends HashMap<String, Object> implements HttpStatusAPI {
    public ResultJson add(String key, Object value) {
        this.put(key, value);
        return this;
    }

    private static ResultJson getJson(Integer code, String msg) {
        ResultJson json = new ResultJson();
        json.put(CODE_TAG, code);
        json.put(MSG_TAG, msg);
        return json;
    }

    public static ResultJson success() {
        return getJson(DEFAULT_HTTP_SUCCESS_CODE, DEFAULT_HTTP_SUCCESS_MSG);
    }
    public static ResultJson data(Object obj) {
        return success().add("data",obj);
    }
    public static ResultJson rows(Object obj) {
        return success().add("rows",obj);
    }
    public static ResultJson success(Integer code) {
        return getJson(code, DEFAULT_HTTP_SUCCESS_MSG);
    }

    public static ResultJson success(String msg) {
        return getJson(DEFAULT_HTTP_SUCCESS_CODE, msg);
    }

    public static ResultJson success(Integer code, String msg) {
        return getJson(code, msg);
    }

    public static ResultJson fail() {
        return getJson(DEFAULT_HTTP_ERROR_CODE, DEFAULT_HTTP_ERROR_MSG);
    }

    public static ResultJson fail(Integer code) {
        return getJson(code, DEFAULT_HTTP_ERROR_MSG);
    }

    public static ResultJson fail(String msg) {
        return getJson(DEFAULT_HTTP_ERROR_CODE, msg);
    }

    public static ResultJson fail(Integer code, String msg) {
        return getJson(code, msg);
    }
}
